from typing import List

from langgraph.graph import add_messages, StateGraph
from typing_extensions import TypedDict, Annotated
from langchain_core.messages import BaseMessage, AIMessage,HumanMessage


class ChatState(TypedDict):
    message_history:Annotated[List[BaseMessage],add_messages]
    user_input:str
    tool_output:str

# 自定义规约函数
def reducer_extend_unique(left:List[str] | None, right:List[str]|None) -> List[str]:
    exists_items = left if left else []
    new_items = right if right else []
    combines = exists_items + new_items
    return list(set(combines))


cs = ChatState()
cs['message_history'] =[]
left = HumanMessage(content='conte')
right = HumanMessage(content='conte')
cs['message_history'].append(add_messages(left,right))
print(cs)
# builder = StateGraph(ChatState)